//
// Created by 12992 on 24-10-13.
//

#include "process.hpp"

#include <thread>
#include <gtest/gtest.h>
#include <glog/logging.h>
#include "video_meta.h"
#include "general_demuxer.h"
#include "../src/include/muxer/general_muxer.h"

TEST(process_test, video_meta)
{
    utils::video_meta meta1(VIDEO_PATH);
    LOG(INFO) << "video encoder : " << meta1.get_video_encoder_type();
    LOG(INFO) << "video format : " << meta1.get_video_format();
    LOG(INFO) << "video framerate : " << meta1.get_video_framerate();
    LOG(INFO) << "audio encoder : " << meta1.get_audio_encoder_type();
    LOG(INFO) << "audio samplerate : " << meta1.get_audio_sample_rate();
    LOG(INFO) << "audio layout : " << meta1.get_audio_channel_layout();
}

TEST(process_test, process_run)
{
    utils::video_meta meta1(VIDEO_PATH);
    auto demuxer1 = std::make_shared<demuxer::general_demuxer>(VIDEO_PATH);
    utils::process process(meta1, [demuxer1](std::shared_ptr<interfaces::muxer>& muxer)
    {
        std::vector<interfaces::packet_provider*> providers;
        for (auto& item: demuxer1->get_streams())
        {
            providers.push_back(item.get());
            muxer = std::make_shared<muxer::general_muxer>(VIDEO_OUTPUT_PATH, providers);
        }
    });
    process.start_process();
}

TEST(process_test, process_run_async)
{
    utils::video_meta meta1(VIDEO_PATH);
    auto demuxer1 = std::make_shared<demuxer::general_demuxer>(VIDEO_PATH);
    utils::process process(meta1, [demuxer1](std::shared_ptr<interfaces::muxer>& muxer)
    {
        std::vector<interfaces::packet_provider*> providers;
        for (auto& item: demuxer1->get_streams())
        {
            providers.push_back(item.get());
            muxer = std::make_shared<muxer::general_muxer>(VIDEO_OUTPUT_PATH, providers);
        }
    });
    process.start_process();
    using namespace std;
    std::this_thread::sleep_for(2ms);
    process.pause_process();
    process.continue_process();
    this_thread::sleep_for(100ms);
    ASSERT_EQ(process.get_status(), utils::process::status::DONE);
}
